/***********************************************************************/
/*                                                                     */
/*  FILE        :initsct.h                                             */
/*  DATE        :Fri, Jan 17, 2014                                     */
/*  DESCRIPTION :define the macro for initialization of sections.      */
/*  CPU GROUP   :64                                                    */
/*                                                                     */
/*  This file is generated by Renesas Project Generator (Ver.4.19).    */
/*  NOTE:THIS IS A TYPICAL EXAMPLE.                                    */
/***********************************************************************/
/*********************************************************************
*
* Device     : M16C/64,65
*
* File Name  : initsct.h
*
* Abstract   : Define the macro for initialization of sections.
*              (note: Do not modify)
*
* History    : 1.20  (2009-01-27)
*
* Copyright (C) 2009 (2010) Renesas Electronics Corporation.
* and Renesas Solutions Corporation. All rights reserved.
*
*********************************************************************/
#include "cstartdef.h"

#pragma section program interrupt

#if __WATCH_DOG__ != 1

#define	sclear(X,Y,Z)	_asm("	.initsct "X","Y","Z"\n"\
			"	mov.b	#00H,R0L\n"\
			"	mov.w	#(topof	"X") ,A1\n"\
			"	mov.w	#sizeof	"X",R3\n"\
			"	sstr.b")

#define scopy(X,Y,Z)	_asm("	.initsct "X","Y","Z"\n"\
			"	.initsct "X"I,rom"Y",noalign\n"\
			"	mov.w	#(topof "X"I)&0ffffH,A0\n"\
			"	mov.b	#(topof "X"I)>>16,R1H\n"\
			"	mov.w	#(topof "X")&0ffffH,A1\n"\
			"	mov.w	#sizeof	"X",R3\n"\
			"	smovf.b")

#else


#define	sclear(X,Y,Z)	_asm("	.initsct "X","Y","Z"\n"\
			"	N_BZERO	"X"")

#define scopy(X,Y,Z)	_asm("	.initsct "X","Y","Z"\n"\
			"	.initsct "X"I,rom"Y",noalign\n"\
			"	scopy	"X"I,"X"")
#endif

#define sclear_f(X,Y,Z)	_asm("	.initsct "X","Y","Z"\n"\
			"	push.w	#(sizeof "X")>>16\n"\
			"	push.w	#(sizeof "X")&0ffffH\n"\
			"	push.w	#(topof "X")>>16\n"\
			"	push.w	#(topof "X")&0ffffH\n"\
			"	.stk	8\n"\
			"	.glb	_bzero\n"\
			"	.call	_bzero,G\n"\
			"	jsr.a	_bzero\n"\
			"	add.b	#8H,sp\n"\
			"	.stk	-8")

#define	scopy_f(X,Y,Z)	_asm("	.initsct "X","Y","Z"\n"\
			"	.initsct "X"I,rom"Y",noalign\n"\
			"	push.w	#(sizeof "X") >> 16\n"\
			"	push.w	#(sizeof "X") & 0ffffH\n"\
			"	push.w	#(topof "X") >> 16\n"\
			"	push.w	#(topof "X") & 0ffffH\n"\
			"	push.w	#(topof "X"I) >> 16\n"\
			"	push.w	#(topof "X"I) & 0ffffH\n"\
			"	.stk	12\n"\
			"	.glb	_bcopy\n"\
			"	.call	_bcopy,G\n"\
			"	jsr.a	_bcopy\n"\
			"	add.b	#12,sp\n"\
			"	.stk	-12")

#if __WATCH_DOG__ == 1
#pragma ASM
scopy		.macro	FROM_,TO_
		mov.w	#(topof FROM_)&0FFFFH,A0
		mov.b	#(topof FROM_)>>16,R1H
		mov.w	#(topof TO_),A1
		mov.w	#(sizeof TO_),R2
		.local M1
	M1:
		mov.b	#00h,037DH
		mov.b	#0FFH,037DH
		cmp.w	#0000h,R2
		.local	M2
		jz		M2
		mov.w	#40,R3
		cmp.w	R3,R2
		.local	M3
		jc		M3
		mov.w	R2,R3
	M3:
		sub.w	R3,R2
		smovf.b
		jmp		M1
	M2:
		.endm

N_BZERO		.macro	SECT_
		mov.w	#(topof SECT_),A1
		mov.w	#0000H,R0
		mov.w	#(sizeof SECT_),R2
		.local	M1	
	M1:
		mov.b	#00h,037DH
		mov.b	#0FFH,037DH
		cmp.w	#0000h,R2
		.local	M2
		jz		M2
		mov.w	#100,R3
		cmp.w	R3,R2
		.local	M3
		jc		M3
		mov.w	R2,R3
	M3:
		sub.w	R3,R2
		sstr.b
		jmp		M1
	M2:
	.endm
#pragma ENDASM
#endif

